home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume7 / lp-remote < prev    next >
Encoding:
Text File  |  1989-07-08  |  9.5 KB  |  338 lines

  1. Newsgroups: comp.sources.misc
  2. Message-Id: <8906201133.AA01854@gizmo.oasis.icl.stc.co.uk>
  3. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  4. Subject: v07i062: a remote printer script for System V
  5. Reply-To: Paul Blackburn <mcvax!oasis.icl.stc.co.uk!mpb@uunet.UU.NET>
  6.  
  7. Posting-number: Volume 7, Issue 62
  8. Submitted-by: Paul Blackburn <mcvax!oasis.icl.stc.co.uk!mpb@uunet.UU.NET>
  9. Archive-name: lp-remote
  10.  
  11. [I wonder how many times this particular wheel has been re-invented?  I've
  12. done a few of these myself (one each for uucp and WIN/3B); however, it's
  13. abotu time someone actually *posted* one.  ++bsa]
  14.  
  15. I enclose a remote printer script which I have written and found to be
  16. very handy for sharing expensive printers.
  17.  
  18. It has been tested on System V but not BSD.
  19. [Won't work under BSD:  they use a different spooler.  ++bsa]
  20. -- 
  21. Cheers,     "did Bostic really send the fix or was it his evil twin, Skippy?"
  22.        Paul Blackburn, ICL, Lovelace Road, Bracknell, Berkshire, RG12 4SN, UK
  23. mpb@oasis.icl.stc.co.uk  OR  ...!uunet!mcvax!ukc!iclbra!mpb
  24. ------------------------------------------cut here---------------------------
  25. #! /bin/sh
  26. # This is a shell archive, meaning:
  27. # 1. Remove everything above the #! /bin/sh line.
  28. # 2. Save the resulting text in a file.
  29. # 3. Execute the file with /bin/sh (not csh) to create the files:
  30. #    remotelp
  31. # This archive created: Fri Jun 16 16:13:24 1989
  32. export PATH; PATH=/bin:$PATH
  33. if test ! -d 'remotelp'
  34. then
  35.     echo shar: creating directory "'remotelp'"
  36.     mkdir 'remotelp'
  37. fi
  38. echo shar: entering directory "'remotelp'"
  39. cd 'remotelp'
  40. echo shar: extracting "'README'" '(2899 characters)'
  41. if test -f 'README'
  42. then
  43.     echo shar: will not over-write existing file "'README'"
  44. else
  45. sed 's/^X//' << \SHAR_EOF > 'README'
  46. XRemote printer script installation notes Sys V          mpb 22 Dec 88
  47. X----------------------------------------------          -------------
  48. X
  49. XPre-amble:
  50. X
  51. XThis script was written to allow a set of small UNIX machines
  52. Xto share two expensive laser printers.
  53. X
  54. XIt makes use of uux to transfer the file-to-be-printed to the
  55. Xmachine that has the printer connected.
  56. X
  57. XIt is tried and tested on System V (both .2 and .3) but not
  58. Xon BSD.
  59. X
  60. X1. Files required
  61. X
  62. X   /usr/spool/lp/model/remote
  63. X   /usr/spool/lp/db
  64. X
  65. X2. Adding a new remote printer
  66. X
  67. X   a. Decide on name for new printer (for example, 'laser')
  68. X   b. Make sure you have a working uucp link to the remote machine
  69. X      and that the remote m/c uucp system will allow the 'lp' command
  70. X      to be executed.
  71. X   c. Become superuser
  72. X   d. Shut down the lp scheduler and set up new printer thus:
  73. X
  74. X      cd /usr/lib
  75. X      ./lpshut
  76. X      ./lpadmin -plaser -mremote -v/dev/null
  77. X      ./accept laser
  78. X      enable laser
  79. X      lpstat -t
  80. X
  81. X   e. Re-start the lp scheduler: ./lpsched
  82. X
  83. X   f. Edit the lp database file (/usr/spool/lp/db) to reflect your remote
  84. X      printer configuration.
  85. X
  86. X   First, make sure there is a line beginning with the name of the printer:
  87. X
  88. Xlaser:pluto:CANON::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
  89. X^^^^^
  90. X
  91. X   Second, make sure the second field is the name of the machine
  92. X   to which your local machine has a uucp link.
  93. X
  94. Xlaser:epcfta:CANON::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
  95. X      ^^^^^^
  96. X
  97. X   The third field is a comment field, use a name to describe the printer.
  98. X
  99. Xlaser:epcfta:CANON lbp8::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
  100. X             ^^^^^^^^^^
  101. X
  102. X   The fourth field is for the name of the printer on the remote machine.
  103. X   Normally this would be the same the local print model (i.e. laser).
  104. X   If the remote computer has a different name for the printer you wish
  105. X   to access then set the name here (blank means same name).
  106. X
  107. X   You can see what printers a machine has available by typing: lpstat -t
  108. X
  109. Xlaser:epcfta:CANON lbp8::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
  110. X                       ^^
  111. X
  112. X   The fifth and sixth fields are optional. They specify escape sequences
  113. X   for small and landscape printing on the remote printer. You will need
  114. X   to refer to the printer manual to check these sequences are correct
  115. X   for your remote printer.
  116. X
  117. X   To use these features you would type:
  118. X
  119. X       lp -dlaser -ol myfile        # for landscape
  120. X
  121. X       lp -dlaser -os myfile        # for small printing
  122. X
  123. X
  124. XHave fun,
  125. X
  126. XPaul Blackburn        |  /~~~\          | Mail:    mpb@oasis.icl.stc.co.uk
  127. XICL, Lovelace Road    | (\@,@/)         |   ...!uunet!mcvax!ukc!iclbra!mpb
  128. XBracknell, Berkshire  |  \_=_/     .zZz |      Phone: +44 344 424842 x2648
  129. XRG12 4SN, UK          |  / " \          |         Telex:    22971 STCICL G
  130. X                      |'fly-by-wire' :-)|              Fax: +44 344 487832
  131. SHAR_EOF
  132. fi # end of overwriting check
  133. echo shar: extracting "'db'" '(1273 characters)'
  134. if test -f 'db'
  135. then
  136.     echo shar: will not over-write existing file "'db'"
  137. else
  138. sed 's/^X//' << \SHAR_EOF > 'db'
  139. X# NAME        /usr/spool/lp/db
  140. X# DATE        Thu Jul 14 13:32:12 BST 1988
  141. X# AUTHOR    Paul Blackburn, DRSBC, ICL, Bracknell
  142. X# PURPOSE    Database of 'remote' printers.
  143. X#        This file is grep'ed by remote printer scripts to get
  144. X#        details for a printer: The format is:
  145. X#
  146. X# <printer>:<next>:<description>:<remote>:<small>:<landscape>
  147. X#
  148. X# Where:
  149. X# M    <printer>    = name of printer used in 'lp -d<printer>'.
  150. X#              This field is mandatory.
  151. X#
  152. X# M    <next>        = name of next machine to uux to.
  153. X#              This field is mandatory.
  154. X#
  155. X# O    <description>    = description of printer
  156. X#              This field is optional.
  157. X#
  158. X# O    <remote>    = name of printer of remote machine (usually
  159. X#              same as <printer>, defaults to same)
  160. X#              This field is optional.
  161. X#
  162. X# O    <small>        = printer command to switch to small print
  163. X#              This field is optional.
  164. X#
  165. X# O    <landscape>    = printer command to switch to L/S print
  166. X#              This field is optional.
  167. X#
  168. X# The commands for small and landscape are escape sequences and are
  169. X# 'echo'ed to the printer.
  170. X#
  171. X# NB as ':' is used to delimit fields use '\072' in command sequences
  172. X#laser:pluto:RICOH:lzr:"\033\022D3 \c:\033\022D4 \c:
  173. X
  174. Xlbp8:pluto:CANON::\033;\033[2 K\033[4 L\033\072\c:\033;\033[15;+;+p\c:
  175. Xlaser:gator:RICOH:pookie:"\033\022D3 \c:\033\022D4 \c:
  176. Xdevps:pebbles:PostScript::::
  177. Xml193p:tigger:::::
  178. SHAR_EOF
  179. fi # end of overwriting check
  180. echo shar: extracting "'remote'" '(2982 characters)'
  181. if test -f 'remote'
  182. then
  183.     echo shar: will not over-write existing file "'remote'"
  184. else
  185. sed 's/^X//' << \SHAR_EOF > 'remote'
  186. X# NAME        /usr/spool/lp/model/remote
  187. X# DATE        Thu Jul 14 13:31:26 BST 1988
  188. X# AUTHOR    Paul Blackburn, DRSBC, ICL, Bracknell
  189. X# PURPOSE    This is a 'remote' spooler script for any printer.
  190. X#        This works by sending a 'uux' print request to a neighboring
  191. X#        machine (NEXT).
  192. X#
  193. X#        This is a 'data-driven' script...
  194. X#        /usr/spool/lp/db is used to get data for a particular printer.
  195. X#
  196. X#        (local) Options:
  197. X#
  198. X#            -os    = small print (portrait)
  199. X#            -ol    = small print (landscape)
  200. X
  201. XLOG=/usr/spool/lp/log
  202. XDB=/usr/spool/lp/db
  203. XMODEL=`basename $0`
  204. XTEMP=/usr/tmp/${MODEL}.$$
  205. X
  206. Xif [ ! -f ${DB} ]
  207. Xthen
  208. X    echo "${MODEL}: unable to open ${DB}" >>$LOG
  209. X    echo "${MODEL}: aborted" >>$LOG
  210. X    exit 1
  211. Xfi
  212. X
  213. Xgrep "^${MODEL}:" ${DB} >${TEMP}
  214. X
  215. XDATA=`cat ${TEMP}`
  216. X
  217. Xif [ -z "${DATA}" ]
  218. Xthen
  219. X    echo "${MODEL}: unable to get data from ${DB}" >>$LOG
  220. X    echo "${MODEL}: aborted" >>$LOG
  221. X    rm -f ${TEMP}
  222. X    exit 1
  223. Xfi
  224. X
  225. XNEXT=`cut -f2 -d":" <${TEMP}`
  226. XDESC=`cut -f3 -d":" <${TEMP}`
  227. XRMODEL=`cut -f4 -d":" <${TEMP}`
  228. Xif [ -z "${RMODEL}" ]
  229. Xthen
  230. X    RMODEL=${MODEL}
  231. Xfi
  232. XSMALL=`cut -f5 -d":" <${TEMP}`
  233. XLAND=`cut -f6 -d":" <${TEMP}`
  234. Xrm -f ${TEMP}
  235. X
  236. Xecho "${MODEL}: DESC=${DESC}, NEXT=${NEXT}" >>$LOG
  237. X
  238. Xif [ -z "${NEXT}" ]
  239. Xthen
  240. X    echo "${MODEL}: unable to determine next machine" >>$LOG
  241. X    echo "${MODEL}: aborted" >>$LOG
  242. X    exit 1
  243. Xfi
  244. X
  245. XTITLE=
  246. XOPTIONS=
  247. XCOPIES=
  248. X
  249. Xif [ -n "$3" ]
  250. Xthen
  251. X    TITLE="-t\"$3\""
  252. Xelse
  253. X    user=`grep "^$2:" /etc/passwd | line | cut -d: -f5`
  254. X    if [ -z "$user" ]
  255. X    then
  256. X        user=$2
  257. X    fi
  258. X    TITLE="-t\"${user}\""
  259. Xfi
  260. X
  261. Xif [ -n "$4" ]
  262. Xthen
  263. X    COPIES=-n$4
  264. Xfi
  265. Xparam5=$5
  266. X
  267. Xshift;shift;shift;shift;shift
  268. Xfiles="$*"
  269. X
  270. X# Split out local options from options for remote lp...
  271. X
  272. XLOCALOPT=""
  273. Xfor i in ${param5}
  274. Xdo
  275. X    echo "${MODEL}: option=${i}" >>${LOG}
  276. X    case "${i}" in
  277. X        s|l ) # local options
  278. X            LOCALOPT="${LOCALOPT} ${i}"
  279. X            ;;
  280. X        * ) # other options simply passed to remote lp
  281. X            OPTIONS="${OPTIONS} -o${i}"
  282. X            ;;
  283. X    esac
  284. Xdone
  285. X
  286. XOPTIONS="${OPTIONS} -oh"
  287. Xif [ -z "${LOCALOPT}" ]
  288. Xthen
  289. X    cat ${files}|uux - -n ${NEXT}!lp ${COPIES} ${OPTIONS} -d${RMODEL}
  290. Xelse
  291. X    LOCALOPT=`echo ${LOCALOPT}`
  292. X    for i in "${LOCALOPT}"
  293. X    do
  294. X        echo "${MODEL}: local option=${i}" >>${LOG}
  295. X        case "${i}" in
  296. X            s ) # small print (portrait)
  297. X                if [ -z "${SMALL}" ]
  298. X                then
  299. X                    echo "${MODEL}: no small cmd\c" >>${LOG}
  300. X                    echo " found in ${DB}" >>${LOG}
  301. X                else
  302. X#                    echo "${MODEL}: small cmd:" >>${LOG}
  303. X#                    echo "${SMALL}" | od -cx >>$LOG
  304. X                    echo "${SMALL}"
  305. X                fi
  306. X                ;;
  307. X            l ) # small print (landscape)
  308. X                if [ -z "${LAND}" ]
  309. X                then
  310. X                    echo "${MODEL}: no land cmd\c" >>${LOG}
  311. X                    echo " found in ${DB}" >>${LOG}
  312. X                else
  313. X#                    echo "${MODEL}: land cmd:" >>${LOG}
  314. X#                    echo "${LAND}" | od -cx >>$LOG
  315. X                    echo "${LAND}"
  316. X                fi
  317. X                ;;
  318. X            * ) # unknown!
  319. X                echo "${MODEL}: unknown local option" >>${LOG}
  320. X                ;;
  321. X        esac
  322. X    done|cat - ${files}|uux - -n ${NEXT}!lp ${COPIES} ${OPTIONS} -d${RMODEL}
  323. Xfi
  324. X
  325. Xecho "${MODEL}: COPIES=${COPIES}, OPTIONS=${OPTIONS}, TITLE=${TITLE}" >> ${LOG}
  326. Xecho "${MODEL}: warning - ignoring title" >> ${LOG}
  327. Xecho "${MODEL}: completed on `date` for ${NEXT}" >> ${LOG}
  328. Xexit 0
  329. SHAR_EOF
  330. chmod +x 'remote'
  331. fi # end of overwriting check
  332. echo shar: done with directory "'remotelp'"
  333. cd ..
  334. #    End of shell archive
  335. exit 0
  336.  
  337.  
  338.